package com.serene.authority.admin.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.serene.authority.admin.entity.vo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 用户表
 *
 * @author serene
 * @createTime 2020/7/10
 */

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class MyUser extends BaseEntity {
    private static final long serialVersionUID = -6525908145032868837L;

    /**
     * 用户自增id
     */
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    /**
     * 部门id
     */
    private Integer deptId;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户昵称
     */
    private String nickName;

    /**
     * 电话
     */
    private String phone;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 状态
     */
    private Integer status;

    public interface Status {
        int LOCKED = 0;
        int VALID = 1;
    }

    /**
     * 角色id
     */
    @TableField(exist = false)
    private Integer roleId;

    /**
     * 岗位组
     */
    @TableField(exist = false)
    private Integer[] jobIds;

    /**
     * 判断是否为admin用户
     *
     * @return
     */
    public boolean isAdmin() {
        return isAdmin(this.getUserId());
    }

    public static boolean isAdmin(Integer userId) {
        return userId != null && 1L == userId;
    }

    public MyUser(Integer userId) {
        this.setUserId(userId);
    }
}
